package com.ljf.admin.controller;


import com.ljf.admin.POJO.VO.LoginBodyVO;
import com.ljf.admin.event.LogEvent;
import com.ljf.framework.Async.AsyncManager;
import com.ljf.framework.result.JsonResult;
import com.ljf.framework.router.LjfRouterConstants;
import com.ljf.framework.security.LjfSecurityManager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: lijinfeng
 * @Date: 2022/4/23
 * @Description 描述:
 */
@RestController
public class LoginController {


    /**
     * 登录接口
     * description: 登录接口
     * author: lijinfeng
     * date: 2022/5/31
     * param: [loginUser] username String，password String
     *
     * @return: com.ljf.common.POJO.VO.JsonResult
     */
    @PostMapping(LjfRouterConstants.LOGIN_ROUTER)
    public JsonResult login(@RequestBody LoginBodyVO loginUser) {
        AsyncManager.supplyAsync(new LogEvent());
        return LjfSecurityManager.doLogin(loginUser.getUsername(), loginUser.getPassword());
    }

    /**
     * 登出接口
     * @return
     */
    @PutMapping(LjfRouterConstants.LOGIN_OUT_ROUTER)
    public JsonResult loginOut() {
        return LjfSecurityManager.doLogout();
    }

}
